package com.ghsc.ghxc.jsb.ui.integral

import androidx.lifecycle.MutableLiveData
import com.cn.appcore.base.BaseViewModel
import com.cn.appcore.ext.executeListResponse
import com.cn.appcore.ext.executeResponse
import com.cn.appcore.http.bean.BaseListResponse
import com.cn.appcore.http.bean.BaseResponse
import com.ghsc.ghxc.jsb.api.ApiMarket
import com.ghsc.ghxc.jsb.ui.home.bean.ResultSku
import com.ghsc.ghxc.jsb.ui.integral.bean.HomeIntegralListResult
import com.ghsc.ghxc.jsb.ui.integral.bean.IntegralGoodsDetailsResult
import com.ghsc.ghxc.jsb.ui.integral.bean.IntegralOrderDetailResult
import com.ghsc.ghxc.jsb.ui.integral.bean.IntegralOrderListResult
import com.ghsc.ghxc.jsb.ui.integral.bean.IntegralOrderResult
import com.ghsc.ghxc.jsb.ui.integral.bean.IntegralResult
import com.ghsc.ghxc.jsb.ui.integral.bean.IntegralSkuResult
import com.ghsc.ghxc.jsb.ui.integral.bean.KuaiDiListResult
import com.ghsc.ghxc.jsb.ui.integral.bean.MyReleaseResult
import com.ghsc.ghxc.jsb.ui.integral.bean.SellListResult
import com.ghsc.ghxc.jsb.ui.integral.bean.SubCommodityResult
import com.ghsc.ghxc.jsb.ui.integral.bean.TypeResult
import com.ghsc.ghxc.jsb.ui.my.bean.AddressDetailBean
import com.ghsc.ghxc.jsb.ui.my.bean.OrderBean
import com.ghsc.ghxc.jsb.ui.my.bean.OrderDetailResult
import com.ghsc.ghxc.jsb.ui.my.bean.OssTokenResultDataBean
import com.ghsc.ghxc.jsb.ui.my.bean.UserResultDataBean
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext

/**
 * 项目：GuoHuaJsb
 * 包名：com.ghsc.ghxc.jsb.ui.integral
 * 类名：IntegralSupermarketViewModel
 * 创建时间：2024/5/20 10:39
 * 创建人 @author： xiaolin
 * 描述 ：Todo...
 */
class IntegralSupermarketViewModel : BaseViewModel() {


    /**
     * 用户信息
     */
    val onShopuserInfoData: MutableLiveData<BaseResponse<IntegralResult>> = MutableLiveData()
    fun onShopuserInfoMethod() {
        launch {
            val response = withContext(Dispatchers.IO) { ApiMarket.service.onShopuserInfoData() }
            executeResponse(
                response,
                { onShopuserInfoData.value = response },
                { againLoginMsg.value = response.msg }
            ) { errorMsg.value = response.msg }
        }

    }
    /**
     * 首页列表
     */
    val onMainIndexData: MutableLiveData<BaseResponse<HomeIntegralListResult>> = MutableLiveData()
    fun onMainIndexMethod(paras: String) {
        launch {
            val response = withContext(Dispatchers.IO) { ApiMarket.service.onMainIndexData(paras) }
            executeResponse(
                response,
                { onMainIndexData.value = response },
                { againLoginMsg.value = response.msg }
            ) { errorMsg.value = response.msg }
        }

    }
    val onGoodListData: MutableLiveData<BaseResponse<HomeIntegralListResult>> = MutableLiveData()
    fun onGoodListMethod(paras: String) {
        launch {
            val response = withContext(Dispatchers.IO) { ApiMarket.service.onGoodListData(paras) }
            executeResponse(
                response,
                { onGoodListData.value = response },
                { againLoginMsg.value = response.msg }
            ) { errorMsg.value = response.msg }
        }

    }




    //我发布的
    var onMyGoodListData = MutableLiveData<BaseResponse<MyReleaseResult>>()
    fun onMyGoodListMethod(paras: String) {
        launch {
            val response = withContext(Dispatchers.IO) { ApiMarket.service.onMyGoodListData(paras) }
            executeResponse(
                response,
                { onMyGoodListData.value = response },
                { againLoginMsg.value = response.msg }
            ) { errorMsg.value = response.msg }
        }
    }

    //我买到的订单列表
    var onShopOrderListData = MutableLiveData<BaseResponse<IntegralOrderListResult>>()
    fun onShopOrderListMethod(paras: String) {
        launch {
            val response = withContext(Dispatchers.IO) { ApiMarket.service.onShopOrderListData(paras) }
            executeResponse(
                response,
                { onShopOrderListData.value = response },
                { againLoginMsg.value = response.msg }
            ) { errorMsg.value = response.msg }
        }
    }
    //我卖出的订单列表
    var onShopSaleOrderListData = MutableLiveData<BaseResponse<SellListResult>>()
    fun onShopSaleOrderListMethod(paras: String) {
        launch {
            val response = withContext(Dispatchers.IO) { ApiMarket.service.onShopSaleOrderListData(paras) }
            executeResponse(
                response,
                { onShopSaleOrderListData.value = response },
                { againLoginMsg.value = response.msg }
            ) { errorMsg.value = response.msg }
        }
    }


    //分类
    var onCatecfgData = MutableLiveData<BaseResponse<TypeResult>>()
    fun onCatecfgMethod(paras: String) {
        launch {
            val response = withContext(Dispatchers.IO) { ApiMarket.service.onCatecfgData(paras) }
            executeResponse(
                response,
                { onCatecfgData.value = response },
                { againLoginMsg.value = response.msg }
            ) { errorMsg.value = response.msg }
        }
    }


    /** 提交商品 **/
    val onSubmitGoodsData: MutableLiveData<BaseResponse<SubCommodityResult>> = MutableLiveData()
    fun onSubmitGoodsMethod(paras:String) {
        launch {
            val response = withContext(Dispatchers.IO) { ApiMarket.service.onSubmitGoodsData(paras) }
            executeResponse(
                response,
                { onSubmitGoodsData.value = response},
                { againLoginMsg.value = response.msg}
            ) { errorMsg.value = response.msg }

        }
    }

    /** 商品详情 **/
    val ontGoodsDetailData: MutableLiveData<BaseResponse<IntegralGoodsDetailsResult>> = MutableLiveData()
    fun ontGoodsDetailDataMethod(paras:String) {
        launch {
            val response = withContext(Dispatchers.IO) { ApiMarket.service.ontGoodsDetailData(paras) }
            executeResponse(
                response,
                { ontGoodsDetailData.value = response},
                { againLoginMsg.value = response.msg}
            ) { errorMsg.value = response.msg }

        }
    }
    /**
     * 规格
     */
    var onSkuDetailData = MutableLiveData<BaseResponse<IntegralSkuResult>>()
    fun onSkuDetailMethod(paras: String) {
        launch {
            val response = withContext(Dispatchers.IO) { ApiMarket.service.onSkuDetailData(paras) }
            executeResponse(
                response,
                { onSkuDetailData.value = response },
                { againLoginMsg.value = response.msg }
            ) { errorMsg.value = response.msg }
        }
    }



    /**
     * 收货地址
     */
    val onAddressListData: MutableLiveData<List<AddressDetailBean>> = MutableLiveData()
    fun onAddressListMethod(paras: String) {
        launch {
            val response = withContext(Dispatchers.IO) { ApiMarket.service.onAddressListData(paras) }
            executeListResponse(
                response,
                { onAddressListData.value = response.data},
                { againLoginMsg.value = response.msg}
            ) { errorMsg.value = response.msg }
        }
    }
    /**
     * 购买
     */
    var onGoodsBuyData = MutableLiveData<BaseResponse<IntegralOrderResult>>()
    fun onGoodsBuyDataMethod(paras: String) {
        launch {
            val response = withContext(Dispatchers.IO) { ApiMarket.service.onGoodsBuyData(paras) }
            executeResponse(
                response,
                { onGoodsBuyData.value = response},
                { againLoginMsg.value = response.msg}
            ) { errorMsg.value = response.msg }
        }
    }


    /**
     * 订单详情
     * @param oid 订单id
     */
    var onIntegralOrderDetail = MutableLiveData<BaseResponse<IntegralOrderDetailResult>>()
    fun onIntegralOrderDetailMethod(paras: String) {
        launch {
            val response = withContext(Dispatchers.IO) { ApiMarket.service.onIntegralOrderDetail(paras) }
            executeResponse(
                response,
                { onIntegralOrderDetail.value = response },
                { againLoginMsg.value = response.msg }
            ) { errorMsg.value = response.msg }
        }
    }




    /**
     * 订单退款
     * @param oid 订单id
     */
    var onShopRefundData = MutableLiveData<BaseResponse<Any>>()
    fun onShopRefundMethod(paras: String) {
        launch {
            val response = withContext(Dispatchers.IO) { ApiMarket.service.onShopRefundData(paras) }
            executeResponse(
                response,
                { onShopRefundData.value = response },
                { againLoginMsg.value = response.msg }
            ) { errorMsg.value = response.msg }
        }
    }

    /**
     * 确认收货
     * @param oid 订单id
     */
    var onShopConfirmData = MutableLiveData<BaseResponse<Any>>()
    fun onShopConfirmMethod(paras: String) {
        launch {
            val response = withContext(Dispatchers.IO) { ApiMarket.service.onShopConfirmData(paras) }
            executeResponse(
                response,
                { onShopConfirmData.value = response },
                { againLoginMsg.value = response.msg }
            ) { errorMsg.value = response.msg }
        }
    }
    /**
     * 订单发货
     */
    var onShopFaHuoData = MutableLiveData<BaseResponse<Any>>()
    fun onShopFaHuoMethod(paras: String) {
        launch {
            val response = withContext(Dispatchers.IO) { ApiMarket.service.onShopFaHuoData(paras) }
            executeResponse(
                response,
                { onShopFaHuoData.value = response },
                { againLoginMsg.value = response.msg }
            ) { errorMsg.value = response.msg }
        }
    }


    /**
     * 删除
     */
    var onDelGoodsData = MutableLiveData<BaseResponse<Any>>()
    fun onDelGoodsMethod(paras: String) {
        launch {
            val response = withContext(Dispatchers.IO) { ApiMarket.service.onDelGoodsData(paras) }
            executeResponse(
                response,
                { onDelGoodsData.value = response },
                { againLoginMsg.value = response.msg }
            ) { errorMsg.value = response.msg }
        }
    }


    /**
     * 上下架
     */
    var onUpdIfonSaleData = MutableLiveData<BaseResponse<Any>>()
    fun onUpdIfonSaleMethod(paras: String) {
        launch {
            val response = withContext(Dispatchers.IO) { ApiMarket.service.onUpdIfonSaleData(paras) }
            executeResponse(
                response,
                { onUpdIfonSaleData.value = response },
                { againLoginMsg.value = response.msg }
            ) { errorMsg.value = response.msg }
        }
    }

    /**
     * 更新sku
     */
    var onUpdSkuData = MutableLiveData<BaseResponse<Any>>()
    fun onUpdSkuMethod(paras: String) {
        launch {
            val response = withContext(Dispatchers.IO) { ApiMarket.service.onUpdSkuData(paras) }
            executeResponse(
                response,
                { onUpdSkuData.value = response },
                { againLoginMsg.value = response.msg }
            ) { errorMsg.value = response.msg }
        }
    }
    /**
     * 快递list
     */
    var onKuaiDiListData = MutableLiveData<BaseResponse<KuaiDiListResult>>()
    fun onKuaiDiListMethod(paras: String) {
        launch {
            val response = withContext(Dispatchers.IO) { ApiMarket.service.onKuaiDiListData(paras) }
            executeResponse(
                response,
                { onKuaiDiListData.value = response },
                { againLoginMsg.value = response.msg }
            ) { errorMsg.value = response.msg }
        }
    }

}